package com.itheima.service.impl;

import com.itheima.mapper.OrderSettingMapper;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.OrderSettingVO;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.List;

@Service
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingMapper orderSettingMapper;

    /**
     * 根据年月查询预约设置数据
     * @param yearMonth
     * @return
     */
    @Override
    public List<OrderSettingVO> findByYearMonth(String yearMonth) {
        //将参数 2024-8 格式化为 2024-08
        String[] parts = yearMonth.split("-");
        String year = parts[0];
        String month = parts[1];
        DecimalFormat df = new DecimalFormat("00");
        String monthPart = df.format(Integer.valueOf(month)); // 将月份格式化为两位数
        yearMonth = year + "-" + monthPart;

        List<OrderSettingVO> list = orderSettingMapper.findByYearMonth(yearMonth);
        return list;
    }

    /**
     * 根据日期修改可预约人数
     * @param orderSetting
     */
    @Override
    public void editNumberByOrderDate(OrderSetting orderSetting) {
        orderSettingMapper.editNumberByOrderDate(orderSetting);
    }
}
